<?php

class W3a_admin extends CI_Controller{

	function __construct(){
		parent::__construct();
		$this->load->database();
		$this->load->helper('url');
	
	}
	
	//获取全部文章
	function article_show(){
	
		$sql = 'select * from w3a_news';
		$res = $this->db->query($sql);
		return $res->result();
	}
	//添加文章
	function add_article($data){
		//$sql = 'insert into w3a_news(news_title,news_content,news_parent_id) value(?,?,?)';
		$res = $this->db->insert('w3a_news',$data);
		return $res;
	}
	
	//添加分类
	function add_category($data){
		$sql = 'insert into w3a_type(w3a_type) value(?)';
		$res = $this->db->query($sql,$data);
		return $res;
	}
	//获取分类列表
	function get_CatList(){
		$sql = 'select * from w3a_type';
		$res = $this->db->query($sql);
		return $res->result();
	}
	//通过ID找category
	function cat_name($art_id){
		$sql = 'select w3a_type from w3a_type where w3a_type_id = ' .$art_id;
		$res = $this->db->query($sql);
		return $res->result();
	}
	//查找一篇文章
	function fine_art($art_id){
		$sql = 'select * from w3a_news where news_id = '.$art_id;
		$res = $this->db->query($sql);
		return $res->result();
	}
	//获取网站信息
	function get_mes(){
		$res = $this->db->query('select * from w3a_manager');
		return $res->result();
	}
	//更新网站信息
	function update_mes($data){
		$res = $this->db->query("update w3a_manager set index_logo='".$data['index_logo']."',index_gov='".$data['index_gov']."',index_tel='".$data['index_tel']."',index_name='".$data['index_name']."',index_desc='".$data['index_desc']."',keyword='".$data['keyword']."' where id = 1");
		return $res;
	}

	//修改文章
	function edit_article($data){
		$sql = "update w3a_news set news_title = ".$data['news_title'].",news_content = ".$data['news_content'].",news_parent_id = ".$data['news_parent_id'];
		$res = $this->db->query($sql);
		return $res->affected_rows();
	}
	//修改栏目
	function edit_category($w3a_type){
		$sql = "update w3a_type ser w3a_type=".$w3a_type;
		$res = $this->db->query($sql);
		return $res->affected_rows();
	}

	
	//删除文章
	function del_article($art_id){
		$sql = "update w3a_news set is_del = 1 where news_id = ".$art_id;
		$res = $this->db->query($sql);
		return $this->db->affected_rows();
	}
	//恢复文章
	function remove($art_id){
		$sql = "update w3a_news set is_del = 0 where news_id = ".$art_id;
		$res = $this->db->query($sql);
		return $this->db->affected_rows();
	}
	//获取回收站中的文章
	function get_remove(){
		$sql = "select * from w3a_news where is_del = 1";
		$res = $this->db->query($sql);
		return $res ->result();
	}
	
	//彻底删除文章
	function del_article_long_time(){
		$sql = "delect * from w3a_news where news_id=".$this->url->segment(4);
		$res = $this->db->query($sql);
		return $this->db->affected_rows();
	}
}


?>